package com.xpgk.app.customer;

import java.util.List;

import com.jfinal.log.Log;
import com.jfinal.plugin.activerecord.Record;
import com.xpgk.app.base.AppBaseController;
import com.xpgk.dto.AjaxRender;
import com.xpgk.mvc.bentryRegister.Customer;
import com.xpgk.mvc.bentryRegister.CustomerDetail;

public class AppCustomerInfoController extends AppBaseController {

	@SuppressWarnings("unused")
	private static final Log log = Log.getLog(AppCustomerInfoController.class);
	private AppCustomerInfoService appCustomerInfoService;

	/**
	 * 录入顾客性别和年龄并测算结果
	 * 
	 */
	// @Before(AppCustomerInfoValidator.class)
	public void saveCustomer() {
		Customer customer = getModel(Customer.class);
		if (!customer.update()) {
			render(AjaxRender.error("更新顾客信息失败！"));
			return;
		}
		CustomerDetail customerDetail = getModel(CustomerDetail.class);
		customerDetail.set(CustomerDetail.column_customerIds, customer.getPKValue());
		if (!customerDetail.save()) {
			render(AjaxRender.error("更新顾客信息失败！"));
			return;
		}
		Record tem = AppCustomerInfoService.getTempResult(customer.getStr(Customer.column_sex),
				customerDetail.getInt(CustomerDetail.column_height), customer.getInt(Customer.column_age),
				customerDetail.getFloat(CustomerDetail.column_firstWeight));

		render(AjaxRender.success().addData("result", tem));
	}

	/**
	 * 获取推荐门店
	 */
	public void getMentionOrgan() {
		String xzqh = getPara("xzqh");
		List<Record> organs = appCustomerInfoService.getMentionOrgan(xzqh);
		render(AjaxRender.success().addData("result", organs));
	}
	
	/**
	 * 手动选择地址，获取推荐门店
	 */
	public void getMentionOrganByAddress() {
		String xzqh = getPara("sdxz");
		List<Record> organs = appCustomerInfoService.getMentionOrganByAddress(xzqh);
		render(AjaxRender.success().addData("result", organs));
	}
	
	/**
	 * 获取首页的体重显示
	 */
	public void getWeight() {
		String customerIds = getPara("customerIds");		
		Record tem = AppCustomerInfoService.getWeight(customerIds);
		render(AjaxRender.success().addData("result", tem));
	}
	/**
	 * 获取体重折线图数据
	 */
	public void getWeightList() {
		String customerIds = getPara("customerIds");
		List<Record> weight = appCustomerInfoService.getWeightList(customerIds);
		render(AjaxRender.success().addData("result", weight));
		
	}
	
	/**
	 * 获取首页的用户产品
	 */
	public void getProduct() {
		String customerIds = getPara("customerIds");
		List<Record> product = appCustomerInfoService.getProduct(customerIds);
		render(AjaxRender.success().addData("result", product));
	}
	
	/**
	 * 获取首页的计划到店次数
	 */
	public void getInStore() {
		String customerIds = getPara("customerIds");		
		Record tem = AppCustomerInfoService.getInStore(customerIds);
		render(AjaxRender.success().addData("result", tem));
	}
	
	/**
	 * 获取首页的实际到店次数
	 */
	public void getTrueInStore() {
		String customerIds = getPara("customerIds");		
		Record tem = AppCustomerInfoService.getTrueInStore(customerIds,customerIds,customerIds);
		render(AjaxRender.success().addData("result", tem));
	}
	
	/**
	 * 获取首页的围度信息
	 */
	public void getGirth() {
		String customerIds = getPara("customerIds");
		String girth = getPara("girth");
		List<Record> product = appCustomerInfoService.getGirth(customerIds,girth);
		render(AjaxRender.success().addData("result", product));
		
	}
	
}
